(function() {
  'use strict';
  angular.module('controllers.dataManager.dataQualityMonitor')
    .controller('businessFluctuationAlarmCtrl', businessFluctuationAlarmCtrl);

  function businessFluctuationAlarmCtrl($scope, $http, COREDATA, businessFluctuationAlarmService, $filter, CoreLoading, dataQualityMonitorService) {
    $scope.flag = {
      state: true,
      arrow: false,
      show: 'table'
    };
    var param = {};
    var time = new Date();
    var date = new Date(time.getFullYear(), time.getMonth(), time.getDate() - 1);
    $scope.params = {
      date: date,
      businessCodes: 0,
      alarmTypeCodes: 0
    };
    $scope.send = {
      page: {
        currentPage: 1,
        pageSize: '10'
      }
    };
    $scope.pageItems = ['10', '20', '40'];
    $scope.businessLineNames = COREDATA.BUSINESSLINE;
    $scope.alarmTypes = businessFluctuationAlarmService.alarmTypes();
    $scope.search = function(isPage) {
      $scope.flag.arrow = false;
      if (!$scope.flag.state && !isPage) {
        $scope.flag.state = true;
        return;
      }
      param = angular.copy($scope.params);
      if ($scope.flag.state) {
        param.currentPage = 1;
      } else {
        param.currentPage = $scope.send.page.currentPage;
      }
      param.pageSize = parseInt($scope.send.page.pageSize);
      var time = $filter('date')($scope.params.date, 'yyyy年MM月dd日');
      $scope.title = businessFluctuationAlarmService.fmtTitle(time, $scope.params.businessCodes);
      var sendData = businessFluctuationAlarmService.fmtSendData(param, $scope.businessLineNames, $scope.alarmTypes);
      CoreLoading.setState(true);
      businessFluctuationAlarmService.businessQuery(sendData, function(res) {
        if (res.state === '10000' && res.data.pageData.length >= 1) {
          $scope.items = res.data.pageData;
          $scope.send.page.currentPage = res.data.page.currentPage;
          $scope.send.page.pageSize = res.data.page.pageSize + '';
          $scope.send.page.totalCount = res.data.page.totalCount;
          $scope.flag.show = 'table';
          $scope.flag.state = false;
          $scope.flag.arrow = false;
        } else {
          dataQualityMonitorService.queryError($scope.flag, '查询无数据');
        }
        CoreLoading.setState(false);
      });

    }
    $scope.search();
  }
  businessFluctuationAlarmCtrl.$inject = ['$scope', '$http', 'COREDATA', 'businessFluctuationAlarmService', '$filter', 'CoreLoading', 'dataQualityMonitorService'];
})();